import { OAVComponent, AttributeViewInfo } from '@feng3d/objectview';
import { Datepicker } from '../components/JQueryUI';
import { Span } from '../components/UI';
import { OAVBase } from '../defaults/OAVBase';

@OAVComponent()
export class OAVDatepicker extends OAVBase
{
	label: Span;
	datepicker: Datepicker;

	constructor(attributeViewInfo: AttributeViewInfo)
	{
		super(attributeViewInfo);

		this.label = new Span();
		this.datepicker = new Datepicker();
		this.addChild(this.label);
		this.addChild(this.datepicker);
	}

	initView()
	{
		super.initView();
		this.datepicker.on('change', this.onChange, this);
	}

	dispose()
	{
		this.datepicker.on('change', this.onChange, this);
	}

	updateView()
	{
		this.datepicker.value = this.attributeValue;
	}

	protected onChange()
	{
		this.attributeValue = this.datepicker.value;
	}
}
